<?php
namespace app\index\controller;
use app\model\Feedback as FeedbackModel;
use think\Db;


class Feedback extends Base
{
    public function __construct(){
        $model = new FeedbackModel();
        $this->model = $model;
        parent::__construct();
        
        $page_info = $this->page_info;
        $page_info['title'] = '分类';

        $this->assign([
            'model'=>$this->model,
            'page_info'=>$page_info
        ]);
    }

    public function save(){
        $ulogin = $this->login_user;
        $fields = [
            'must'=>['type','content','msg_id'],
            'nomust'=>[]
        ];
        $params = paramFilter(request()->param(),$fields);
        if (!empty($params['error_msg'])) {
            return json(['code'=>5000,'msg'=>$params['error_msg']]);
        }

        $msg = Db::name('msg')->where('id',$params['msg_id'])->find();
        if (empty($msg) || empty($msg['reply']) || $msg['reply'] == $params['content']) {
            return json(['code'=>2000]);
        }

        $save_data = [
            'user_id'=>$ulogin['id'],
            'assistant_id'=>$msg['assistant_id'],
            'session_sn'=>$msg['session_sn'],
            'message'=>$msg['session_sn'],
            'reply'=>$msg['reply'],
            'type'=>$params['type'],
            'content'=>$params['content'],
            'ctime'=>time()
        ];

        FeedbackModel::insertGetId($save_data);
        $result = [
            'code'=>2000,
        ];
        return json($result);
    }



   
}
